home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v8n03.arc / PCPRINT.C < prev    next >
C/C++ Source or Header  |  1989-01-18  |  3KB  |  110 lines

  1. /* pcprint.c
  2.  *  For MSC 5.0/QuickC: cl pcprint.c
  3.  *  For Turbo C:        tcc -DTURBOC pcprint.c
  4.  */
  5.  
  6. #include<stdio.h>
  7. #include<bios.h>
  8.  
  9.                 /* printer error code bits */
  10. #define PR_TIMEOUT    0x0001
  11. #define UNUSED_1    0x0002
  12. #define UNUSED_2    0x0004
  13. #define PR_IOERR    0x0008
  14. #define PR_SELECT     0x0010
  15. #define PR_PAPEROUT   0x0020
  16. #define PR_ACKNOWLEDGE  0x0040
  17. #define PR_NOTBUSY    0x0080
  18.  
  19. #define PRINT_ERRS 3
  20.  
  21. struct _printerrs
  22. {
  23.   char *errmsg;
  24.   int errval;
  25. } printerrs[PRINT_ERRS] =
  26. {
  27.   "Printer time out", PR_TIMEOUT,
  28.   "I/O Error",PR_IOERR,
  29.   "Out of Paper",PR_PAPEROUT,
  30. };
  31.  
  32.               /* general purpose macros */
  33. #define PRINTER_ERRBITS (PR_TIMEOUT | PR_IOERR | PR_PAPEROUT)
  34. #define LPT1 0
  35. #define LPT2 1
  36. #define PRINTER_TIMEOUT_ADDR  0x00400078
  37. #define PRINTER_WRITE 0
  38.  
  39. /*
  40.  * this function sets the printer timeout to 'val' for printer 'pr'
  41.  */
  42. void SetPrTimer(val, pr)
  43. int val, pr;
  44. {
  45.   unsigned char far *Pr_tim_out = (unsigned char far *)PRINTER_TIMEOUT_ADDR;
  46.  
  47.   Pr_tim_out[pr] = val;        /* set printer time out value */
  48. }
  49.  
  50. /*
  51.  * this function gets the printer timeout value for printer 'pr'
  52.  */
  53. int GetPrTimer(pr)
  54. int pr;
  55. {
  56.   unsigned char far *Pr_tim_out = (unsigned char far *)PRINTER_TIMEOUT_ADDR;
  57.  
  58.   return Pr_tim_out[pr];         /* get printer time out value */
  59. }
  60.  
  61. /* this function prints an error message for the printer error bits set
  62.  * in errval
  63.  */
  64. void PcPrinterr(errval)
  65. unsigned errval;
  66. {
  67.   int i;
  68.  
  69.   printf("\nPrinter error: ");
  70.  
  71.   for( i = 0; i < PRINT_ERRS; i++)
  72.     if(errval & printerrs[i].errval)
  73.       printf(" %s",printerrs[i].errmsg);
  74. }
  75.  
  76. unsigned PcPrint(str, pr)
  77. char *str;
  78. int pr;
  79. {
  80.   unsigned retval;
  81.   
  82.   for( ; *str; str++)
  83. #ifdef TURBOC
  84.     if( (retval = biosprint(PRINTER_WRITE, (unsigned)*str, pr))
  85.        & PRINTER_ERRBITS)
  86. #else
  87.     if( (retval = _bios_printer(PRINTER_WRITE, pr, (unsigned)*str))
  88.        & PRINTER_ERRBITS)
  89. #endif
  90.       return (retval & PRINTER_ERRBITS);
  91.   return 0;
  92. }
  93.  
  94. main()
  95. {
  96.   unsigned retval;
  97.   int oldval;
  98.  
  99.   oldval = GetPrTimer(LPT1);            /* get old timer value */
  100.   SetPrTimer(1,LPT1);                 /* set new timer value */
  101.  
  102.   if(retval = PcPrint("this is a test\n", LPT1))  /* print the string */
  103.     PcPrinterr(retval);               /* report any error */
  104.   else
  105.     printf("\nPrint test was successful");
  106.  
  107.   SetPrTimer(oldval, LPT1);             /* set the timer value */
  108.   exit(0);
  109. }
  110.